package com.haitonghop.modules.local;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;

import com.haitonghop.R;
import com.haitonghop.main.DisplayUtils;

public class ContactMeActivity extends Activity implements OnClickListener {

	Button btnFacebook;
	Button btnSendEmail;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		// Remove notification bar
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.contact_activity_layout);

//		TextView textView = (TextView) findViewById(R.id.titleActivity);
//		textView.setText("Liên hệ");
//
//		Button button = (Button) findViewById(R.id.btnMoreFunctions);
//		button.setVisibility(View.GONE);


		btnFacebook = (Button) findViewById(R.id.btnFacebook);
		btnFacebook.setOnClickListener(this);
		btnFacebook.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String url = "https://www.facebook.com/pages/H%C3%A0i-b%E1%BB%B1a-Community/427416300681862";
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
				startActivity(browserIntent);
			}
		});

		btnSendEmail = (Button) findViewById(R.id.btnSendEmail);
		btnSendEmail.setOnClickListener(this);
		btnSendEmail.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				doContact();
			}
		});

		Button back = (Button) findViewById(R.id.btnBackAcvitity);
		if (back != null) {
			back.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					finish();
				}
			});
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			finish();
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void onClick(View v) {

	}

	private void doContact() {

		AlertDialog.Builder alert = new AlertDialog.Builder(this);
		alert.setTitle("Liên hệ");
		alert.setMessage("Nếu bạn có nhu cầu quảng cáo, quảng bá sản phẩm của mình tới người sử dụng, vui lòng liên hệ tới mình nhé! ^^");
		alert.setPositiveButton("Liên hệ", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {

				Intent i = new Intent(Intent.ACTION_SEND);
				i.setType("message/rfc822");
				i.putExtra(Intent.EXTRA_EMAIL, new String[] { "haibua.contact@gmail.com" });
				i.putExtra(Intent.EXTRA_SUBJECT, "V/v HaiBL Application");
				i.putExtra(Intent.EXTRA_TEXT, "");
				try {
					startActivity(Intent.createChooser(i, "Send mail..."));
				} catch (android.content.ActivityNotFoundException ex) {
					DisplayUtils.openNoticeDialog("Lỗi", "Vui lòng liên hệ \nEmail: haibua.contact@gmail.com", ContactMeActivity.this, null);
					Toast.makeText(ContactMeActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
				}

			}
		});
		alert.setNeutralButton("Thông tin", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				DisplayUtils.openNoticeDialog("Thông tin",  "Vui lòng liên hệ \nEmail: haibua.contact@gmail.com", ContactMeActivity.this, null);
			}
		});
		alert.setNegativeButton("Đóng", null);
		alert.show();

	}
}
